<?php

namespace App\Http\Controllers\Admin;

use View;
use DB;
use Session;
use Redirect;
use App\Model\Feedback;

class FeedbackController extends AdminBaseController
{
    public function __construct()
    {
        $option = ['module_name'=>'feedback','status'=>'status'];
        $this->setModelObj(new Feedback,$option);
    }

	/**
	 * 获取正确的排序组合
     */
    protected function getTrueOrder($data)
    {
        $orderby = [];
        if(!array_key_exists('sort',$data)){
            $orderby['field'] = $this->model_keyname;
            $orderby['type'] = 'desc';
        }else{
            switch ($data['sort']){
                case 'add_time_format':
                    $orderby['field'] = 'add_time';break;
                default:
                    $orderby['field'] = $data['sort'];break;
            }
            $orderby['type'] =  $data['order'];
        }
        return $orderby;
    }

	/**
	 * 获取正确的搜索结果
     */
    protected function getTrueSearch($serachstr)
    {
        if($serachstr){
            foreach($serachstr as $val){
                if(!empty($val['value'])){
                    switch ($val['name']){
                        case 'starttime':
                            $search[] = ['add_time','>',strtotime($val['value'])];
                            break;
                        case 'endtime':
                            $search[] = ['add_time','<',strtotime($val['value'])];
                            break;
                        default:
                            $search[] = [$val['name'],'like','%'.$val['value'].'%'];
                            break;
                    }
                }
            }
            $search = empty($search) ? [] : $search;
        }else{
            $search = [];
        }
        return $search;
    }
}